<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CompanyActive extends Model
{
    public $timestamps = false;
    protected $connection = 'xz';
    protected $table = 'company_active';
    use HasFactory;

    public function org()
    {
        return $this->hasOne('App\Models\Enterprise','id','eid')->select('id','name','full_name','tell');
    }

    public function users()
    {
        return $this->hasManyThrough(
            'App\Models\Personal', //第3表模型
            'App\Models\CompanyActiveAccept', //中间表模型
            'active_id', //中间表中, 对于第1表的外键
            'id', //第3表中, 对于中间表的外键
            'id', //第1表中, 对于中间表的本地键
            'uid' //中间表中, 对于第3表的本地键
        )->select('uid','name','tell');
    }

    public function getActiveStartTimeAttribute(string $value)
    {
        return Date("Y-m-d H:i:s",$value);
    }

    public function getActiveEndTimeAttribute(string $value)
    {
        return Date("Y-m-d H:i:s",$value);
    }

    public function getCreateTimeAttribute(string $value)
    {
        return Date("Y-m-d H:i:s",$value);
    }
}
